package com.sg.service.biz.framework.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.sg.common.util.CommonFunctionHelper;
import com.sg.common.util.RedisUtil;
import com.sg.dto.base.framework.req.*;
import com.sg.dto.biz.framework.req.*;
import com.sg.dto.biz.framework.res.*;
import com.wicket.okrframework.common.annotations.BanAuto;
import com.sg.common.exception.Assert;
import com.wicket.okrframework.dal.po.mbg.*;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author ：
 * @version 1.0
 * @date ：
 */
@Service
public class PlfAuthServiceImpl
        implements com.wicket.okrframework.biz.service.PlfAuthService {

    @Resource
    private RedisUtil redisUtil;
    @Resource
    private MPlatformAuthorizeService mPlatformAuthorizeService;
    @Resource
    private MPrivacyService mPrivacyService;
    @Resource
    private MSceneRoleService mSceneRoleService;
    @Resource
    private MPrivacyDistributionService mPrivacyDistributionService;
    @Resource
    private MHostTypeService mHostTypeService;

    /**
     * D1-1查权限授权列表[1428]
     * gen by moon at 10/2/2022, 12:04:19 AM
     */
    @Trace(operationName = "D1-1查权限授权列表")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Transactional(rollbackFor = Exception.class)
    @BanAuto
    @Override
    public QueryPlfPowerAuthListRespDto queryPlfPowerAuthList(QueryPlfPowerAuthListReqDto reqDto) {


        List<PlatformAuthorize> listPlatformAuthorize_1 = new ArrayList<>();
        List<Privacy> listPrivacy_1 = new ArrayList<>();
//步骤0: 1-1-06查询平台授权范围列表 - queryPlfAuthList
        List<PlatformAuthorize> listPlatformAuthorize = new ArrayList<>();
        QueryPlfAuthListReq queryPlfAuthListReq = new QueryPlfAuthListReq();
        queryPlfAuthListReq.setTypeCode("AUTH");//sourceId:34228_1
        queryPlfAuthListReq.setAuthorizeTypeCode("SENCE");//sourceId:34223_1
        if (reqDto != null) {
            queryPlfAuthListReq.setIsView(reqDto.getIsView());//SimpleFieldAssign//sourceId:34227_1
            queryPlfAuthListReq.setAuthorizedObject(reqDto.getAuthorizedObject());//SimpleFieldAssign//sourceId:34224_1
            queryPlfAuthListReq.setSubjectLifeCycle(reqDto.getSubjectLifeCycle());//SimpleFieldAssign//sourceId:35282_1
            queryPlfAuthListReq.setIsArchive(reqDto.getIsArchive());//SimpleFieldAssign//sourceId:34229_1
        }

        /*1-1-06查询平台授权范围列表[1355]   */
        Assert.isNull(queryPlfAuthListReq.getTypeCode(), "D1-1查权限授权列表-1-1-06查询平台授权范围列表-授权内容类型编码不能为空", false);
        Assert.isNull(queryPlfAuthListReq.getAuthorizeTypeCode(), "D1-1查权限授权列表-1-1-06查询平台授权范围列表-授权对象类型编码不能为空", false);
        Assert.isNull(queryPlfAuthListReq.getAuthorizedObject(), "D1-1查权限授权列表-1-1-06查询平台授权范围列表-授权对象ID不能为空", false);
        listPlatformAuthorize = mPlatformAuthorizeService.queryPlfAuthList(queryPlfAuthListReq);


        listPlatformAuthorize_1 = listPlatformAuthorize;

//步骤1: 1-2-11批量查询权限列表 - batchQueryPowerList
        List<Privacy> listPrivacy = new ArrayList<>();
        if (listPlatformAuthorize != null && listPlatformAuthorize.size() > 0 && listPlatformAuthorize != null && listPlatformAuthorize != null && listPlatformAuthorize.size() > 0) {
            BatchQueryPowerListReq batchQueryPowerListReq = new BatchQueryPowerListReq();
            batchQueryPowerListReq.setPowerIdList(listPlatformAuthorize.stream().map(item -> item.getAuthorizedContentId())
                    .collect(Collectors.toList()));/*list-to-strings*///sourceId:34230_1
            if (reqDto != null) {
                batchQueryPowerListReq.setPrivacyType(reqDto.getPrivacyType());//SimpleFieldAssign//sourceId:34233_1
            }

            /*1-2-11批量查询权限列表[1245]   */

            listPrivacy = mPrivacyService.batchQueryPowerList(batchQueryPowerListReq);


            listPrivacy_1 = listPrivacy;
        }

        QueryPlfPowerAuthListRespDto retData = new QueryPlfPowerAuthListRespDto();
        //数据集融合  MoreListToOneSource
        if (listPlatformAuthorize_1 != null && !CollectionUtil.isEmpty(listPlatformAuthorize_1)) {
            for (PlatformAuthorize platformAuthorize : listPlatformAuthorize_1) {
                PlfAuthDto retElm = new PlfAuthDto();
                retElm.setPlatformAuthorizeId(platformAuthorize.getPlatformAuthorizeId());//SimpleFieldAssign//sourceId:15466_2
                retElm.setAuthorizedContentId(platformAuthorize.getAuthorizedContentId());//SimpleFieldAssign//sourceId:15468_2
                retElm.setSubjectLifeCycle(platformAuthorize.getSubjectLifeCycle());//SimpleFieldAssign//sourceId:15469_2
                retElm.setOperationInductionId(platformAuthorize.getOperationInductionId());//SimpleFieldAssign//sourceId:15470_2
                retElm.setOperateTime(platformAuthorize.getOperateTime());//SimpleFieldAssign//sourceId:15471_2

                if (listPrivacy_1 != null) {
                    for (Privacy privacy : listPrivacy_1) {
                        if (privacy.getPrivacyId().equals(platformAuthorize.getAuthorizedContentId())) {
                            retElm.setPrivacyCode(privacy.getPrivacyCode());//SimpleFieldAssign//sourceId:15473_2
                            retElm.setPrivacyName(privacy.getPrivacyName());//SimpleFieldAssign//sourceId:15474_2
                            retElm.setPrivacyLogo(privacy.getPrivacyLogo());//SimpleFieldAssign//sourceId:28157_2
                            retElm.setStrategyType(privacy.getStrategyType());//SimpleFieldAssign//sourceId:15919_2
                            retData.getPlfAuthList().add(retElm);
                        }
                    }
                }

            }
        }//sourceId:34247_1


        return retData;
    }

    /**
     * D1-1新增平台授权范围[582]
     * gen by moon at 8/10/2022, 3:24:07 AM
     */
    @Trace(operationName = "D1-1新增平台授权范围")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Transactional(rollbackFor = Exception.class)
    @Override
    public AddPlfAuthRespDto addPlfAuth(AddPlfAuthReqDto reqDto) {


        String string_1 = null;
//步骤0: 1-1-06新增平台授权范围 - addPlfAuth
        String string = null;
        PlatformAuthorize platformAuthorize = new PlatformAuthorize();
        if (reqDto != null) {
            platformAuthorize.setTypeCode(reqDto.getTypeCode());//sourceId:35026_1
            platformAuthorize.setAuthorizedContentId(reqDto.getAuthorizedContentId());//sourceId:35027_1
            platformAuthorize.setIsAutoEmpower(reqDto.getIsAutoEmpower());//sourceId:35028_1
            platformAuthorize.setIsView(reqDto.getIsView());//sourceId:35097_1
            platformAuthorize.setAuthorizeTypeCode(reqDto.getAuthorizeTypeCode());//sourceId:35029_1
            platformAuthorize.setAuthorizedObject(reqDto.getAuthorizedObject());//sourceId:35030_1
            platformAuthorize.setSubjectLifeCycle(reqDto.getSubjectLifeCycle());//sourceId:35031_1
        }

        /*1-1-06新增平台授权范围[1437]   */
        Assert.isNull(platformAuthorize.getTypeCode(), "D1-1新增平台授权范围-1-1-06新增平台授权范围-授权内容类型编码不能为空", false);
        Assert.isNull(platformAuthorize.getAuthorizedContentId(), "D1-1新增平台授权范围-1-1-06新增平台授权范围-授权内容ID不能为空", false);
        Assert.isNull(platformAuthorize.getIsAutoEmpower(), "D1-1新增平台授权范围-1-1-06新增平台授权范围-是否自动授权不能为空", false);
        Assert.isNull(platformAuthorize.getIsView(), "D1-1新增平台授权范围-1-1-06新增平台授权范围-空间是否可见不能为空", false);
        Assert.isNull(platformAuthorize.getAuthorizeTypeCode(), "D1-1新增平台授权范围-1-1-06新增平台授权范围-授权对象类型编码不能为空", false);
        Assert.isNull(platformAuthorize.getAuthorizedObject(), "D1-1新增平台授权范围-1-1-06新增平台授权范围-授权对象ID不能为空", false);
        Assert.isNull(platformAuthorize.getSubjectLifeCycle(), "D1-1新增平台授权范围-1-1-06新增平台授权范围-主体生命周期不能为空", false);
        string = mPlatformAuthorizeService.addPlfAuth(platformAuthorize);

        string_1 = string;

        AddPlfAuthRespDto retData = new AddPlfAuthRespDto();
        if (string_1 != null) {
            retData.setPlatformAuthorizeId(string_1);//sourceId:35033_1
        }


        return retData;
    }

    /**
     * D1-1查询角色授权详情[1255]
     * gen by moon at 8/29/2022, 11:59:16 PM
     */
    @Trace(operationName = "D1-1查询角色授权详情")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Transactional(rollbackFor = Exception.class)
    @Override
    public QueryPltRoleAuthDetailRespDto queryPltRoleAuthDetail(QueryPltRoleAuthDetailReqDto reqDto) {


        PlatformAuthorize platformAuthorize_1 = null;
        SceneRole sceneRole_1 = null;
        HostType hostType_1 = null;
//步骤0: 1-1-06查询平台授权范围详情 - queryPlfAuthDetail
        PlatformAuthorize platformAuthorize = null;
        QueryPlfAuthDetailReq queryPlfAuthDetailReq = new QueryPlfAuthDetailReq();
        if (reqDto != null) {
            queryPlfAuthDetailReq.setPlatformAuthorizeId(reqDto.getPlatformAuthorizeId());//sourceId:28950_1
        }

        /*1-1-06查询平台授权范围详情[28]   */
        Assert.isNull(queryPlfAuthDetailReq.getPlatformAuthorizeId(), "D1-1查询角色授权详情-1-1-06查询平台授权范围详情-授权记录ID不能为空", false);
        platformAuthorize = mPlatformAuthorizeService.queryPlfAuthDetail(queryPlfAuthDetailReq);

        platformAuthorize_1 = platformAuthorize;

//步骤1: 1-2-08查询角色详情 - queryRoleDetail
        SceneRole sceneRole = null;
        if (platformAuthorize != null) {
            QueryRoleDetailReq queryRoleDetailReq = new QueryRoleDetailReq();
            if (platformAuthorize != null) {
                queryRoleDetailReq.setRoleId(platformAuthorize.getAuthorizedContentId());//sourceId:28971_1
            }

            /*1-2-08查询角色详情[170]   */
            Assert.isNull(queryRoleDetailReq.getRoleId(), "D1-1查询角色授权详情-1-2-08查询角色详情-角色ID不能为空", false);
            sceneRole = mSceneRoleService.queryRoleDetail(queryRoleDetailReq);

            sceneRole_1 = sceneRole;
        }

//步骤2: 1-1-14查询宿主类型详情 - queryHostTypeDetail
        HostType hostType = null;
        if (sceneRole != null) {
            QueryHostTypeDetailReq queryHostTypeDetailReq = new QueryHostTypeDetailReq();
            if (sceneRole != null) {
                queryHostTypeDetailReq.setHostTypeId(sceneRole.getHostTypeId());//sourceId:29050_1
            }

            /*1-1-14查询宿主类型详情[195]   */
            Assert.isNull(queryHostTypeDetailReq.getHostTypeId(), "D1-1查询角色授权详情-1-1-14查询宿主类型详情-宿主类型ID不能为空", false);
            hostType = mHostTypeService.queryHostTypeDetail(queryHostTypeDetailReq);

            hostType_1 = hostType;
        }

        QueryPltRoleAuthDetailRespDto retData = new QueryPltRoleAuthDetailRespDto();
        if (platformAuthorize_1 != null) {
            retData.setPlatformAuthorizeId(platformAuthorize_1.getPlatformAuthorizeId());//sourceId:29003_1
            retData.setTypeCode(platformAuthorize_1.getTypeCode());//sourceId:29004_1
            retData.setAuthorizedContentId(platformAuthorize_1.getAuthorizedContentId());//sourceId:29005_1
            retData.setAuthorizeTypeCode(platformAuthorize_1.getAuthorizeTypeCode());//sourceId:29013_1
            retData.setIsDefault(platformAuthorize_1.getIsDefault());//sourceId:34136_1
            retData.setAuthorizedObject(platformAuthorize_1.getAuthorizedObject());//sourceId:29009_1
            retData.setIsAutoEmpower(platformAuthorize_1.getIsAutoEmpower());//sourceId:34134_1
            retData.setIsView(platformAuthorize_1.getIsView());//sourceId:34135_1
            retData.setSubjectLifeCycle(platformAuthorize_1.getSubjectLifeCycle());//sourceId:29010_1
            retData.setOperationInductionId(platformAuthorize_1.getOperationInductionId());//sourceId:29011_1
            retData.setOperateTime(platformAuthorize_1.getOperateTime());//sourceId:29012_1
        }
        if (sceneRole_1 != null) {
            retData.setRoleId(sceneRole_1.getRoleId());//sourceId:34137_1
            retData.setRoleLogo(sceneRole_1.getRoleLogo());//sourceId:34138_1
            retData.setRoleCode(sceneRole_1.getRoleCode());//sourceId:29042_1
            retData.setRoleName(sceneRole_1.getRoleName());//sourceId:29043_1
            retData.setRoleType(sceneRole_1.getRoleType());//sourceId:29044_1
            retData.setIsIdentity(sceneRole_1.getIsIdentity());//sourceId:29046_1
            retData.setAutomaticCreation(sceneRole_1.getAutomaticCreation());//sourceId:29047_1
            retData.setPlatformData(sceneRole_1.getPlatformData());//sourceId:29048_1
            retData.setRoleRemark(sceneRole_1.getRoleRemark());//sourceId:34139_1
        }
        if (hostType_1 != null) {
            retData.setHostTypeId(hostType_1.getHostTypeId());//sourceId:34141_1
            retData.setHostTypeName(hostType_1.getHostTypeName());//sourceId:29083_1
        }


        return retData;
    }

    /**
     * D1-1存档平台角色授权[583]
     * gen by moon at 8/29/2022, 11:59:19 PM
     */
    @Trace(operationName = "D1-1存档平台角色授权")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Transactional(rollbackFor = Exception.class)
    @Override
    public ArchivePltRoleAuthRespDto archivePltRoleAuth(ArchivePltRoleAuthReqDto reqDto) {


        //步骤0: 1-1-06查询平台授权范围详情 - queryPlfAuthDetail
        PlatformAuthorize platformAuthorize = null;
        QueryPlfAuthDetailReq queryPlfAuthDetailReq = new QueryPlfAuthDetailReq();
        if (reqDto != null) {
            queryPlfAuthDetailReq.setPlatformAuthorizeId(reqDto.getPlatformAuthorizeId());//sourceId:45217_1
        }

        /*1-1-06查询平台授权范围详情[28]   */
        Assert.isNull(queryPlfAuthDetailReq.getPlatformAuthorizeId(), "D1-1存档平台角色授权-1-1-06查询平台授权范围详情-授权记录ID不能为空", false);
        platformAuthorize = mPlatformAuthorizeService.queryPlfAuthDetail(queryPlfAuthDetailReq);


//步骤1: 1-2-12查询权限分配列表 - queryTributPowerList
        List<PrivacyDistribution> listPrivacyDistribution = new ArrayList<>();
        if (platformAuthorize != null) {
            QueryTributPowerListReq queryTributPowerListReq = new QueryTributPowerListReq();
            queryTributPowerListReq.setTypeCode("ROLE");//sourceId:50855_1
            queryTributPowerListReq.setSubjectLifeCycle("EDITING");//sourceId:50857_1
            queryTributPowerListReq.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID//sourceId:257800_1
            if (platformAuthorize != null) {
                queryTributPowerListReq.setAllocationObjectId(platformAuthorize.getAuthorizedContentId());//sourceId:50856_1
            }

            /*1-2-12查询权限分配列表（正在编辑）[497]   */
            Assert.isNull(queryTributPowerListReq.getTypeCode(), "D1-1存档平台角色授权-1-2-12查询权限分配列表（正在编辑）-分配对象类型编码不能为空", false);
            Assert.isNull(queryTributPowerListReq.getAllocationObjectId(), "D1-1存档平台角色授权-1-2-12查询权限分配列表（正在编辑）-分配对象ID不能为空", false);
            Assert.isNull(queryTributPowerListReq.getSubjectLifeCycle(), "D1-1存档平台角色授权-1-2-12查询权限分配列表（正在编辑）-主体生命周期不能为空", false);
            Assert.isNull(queryTributPowerListReq.getSpaceId(), "D1-1存档平台角色授权-1-2-12查询权限分配列表（正在编辑）-创建于空间ID不能为空", false);
            listPrivacyDistribution = mPrivacyDistributionService.queryTributPowerList(queryTributPowerListReq);


        }

//步骤2: 1-2-12批量删除权限分配 - batchDeleteTributPower
        boolean bOOLEAN;
        if (listPrivacyDistribution != null && listPrivacyDistribution.size() > 0 && listPrivacyDistribution != null && listPrivacyDistribution != null && listPrivacyDistribution.size() > 0) {
            List<String> listString = new ArrayList<>();
            listString = listPrivacyDistribution.stream().map(item -> item.getPrivacyDistributionId())
                    .collect(Collectors.toList());//sourceId:50907_1

            /*1-2-12批量删除权限分配[1553]   */

            bOOLEAN = mPrivacyDistributionService.batchDeleteTributPower(listString);


        }

//步骤3: 1-2-12查询权限分配列表 - queryTributPowerList
        List<PrivacyDistribution> listPrivacyDistribution_2 = new ArrayList<>();
        if (platformAuthorize != null) {
            QueryTributPowerListReq queryTributPowerListReq_1 = new QueryTributPowerListReq();
            queryTributPowerListReq_1.setTypeCode("ROLE");//sourceId:50920_1
            queryTributPowerListReq_1.setSubjectLifeCycle("CURRENTLY_VALID");//sourceId:50922_1
            queryTributPowerListReq_1.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID//sourceId:257801_1
            if (platformAuthorize != null) {
                queryTributPowerListReq_1.setAllocationObjectId(platformAuthorize.getAuthorizedContentId());//sourceId:50921_1
            }

            /*1-2-12查询权限分配列表（当前有效）[497]   */
            Assert.isNull(queryTributPowerListReq_1.getTypeCode(), "D1-1存档平台角色授权-1-2-12查询权限分配列表（当前有效）-分配对象类型编码不能为空", false);
            Assert.isNull(queryTributPowerListReq_1.getAllocationObjectId(), "D1-1存档平台角色授权-1-2-12查询权限分配列表（当前有效）-分配对象ID不能为空", false);
            Assert.isNull(queryTributPowerListReq_1.getSubjectLifeCycle(), "D1-1存档平台角色授权-1-2-12查询权限分配列表（当前有效）-主体生命周期不能为空", false);
            Assert.isNull(queryTributPowerListReq_1.getSpaceId(), "D1-1存档平台角色授权-1-2-12查询权限分配列表（当前有效）-创建于空间ID不能为空", false);
            listPrivacyDistribution_2 = mPrivacyDistributionService.queryTributPowerList(queryTributPowerListReq_1);


        }

//步骤4: 1-2-12批量修改权限分配 - batchUpdateTributPower
        boolean bOOLEAN_1;
        if (listPrivacyDistribution_2 != null && listPrivacyDistribution_2.size() > 0 && listPrivacyDistribution_2 != null && listPrivacyDistribution_2 != null && listPrivacyDistribution_2.size() > 0) {
            List<PrivacyDistribution> listPrivacyDistribution_4 = new ArrayList<>();
            for (PrivacyDistribution item : listPrivacyDistribution_2) {
                PrivacyDistribution oneItem = new PrivacyDistribution();
                oneItem.setPrivacyDistributionId(item.getPrivacyDistributionId());//sourceId:26443_2
                oneItem.setSubjectLifeCycle("ARCHIVING");//sourceId:26444_2
                oneItem.setIsArchive("TRUE");//sourceId:26445_2

                listPrivacyDistribution_4.add(oneItem);
            }//sourceId:50937_1

            /*1-2-12批量修改权限分配[1554]   */

            bOOLEAN_1 = mPrivacyDistributionService.batchUpdateTributPower(listPrivacyDistribution_4);


        }

//步骤5: 1-1-06修改平台授权范围 - updatePlfAuth
        boolean bOOLEAN_2;
        PlatformAuthorize platformAuthorize_2 = new PlatformAuthorize();
        platformAuthorize_2.setSubjectLifeCycle("ARCHIVING");//sourceId:45106_1
        platformAuthorize_2.setIsArchive("TRUE");//sourceId:45107_1
        if (reqDto != null) {
            platformAuthorize_2.setPlatformAuthorizeId(reqDto.getPlatformAuthorizeId());//sourceId:45101_1
        }

        /*1-1-06修改平台授权范围(存档）[1563]   */
        Assert.isNull(platformAuthorize_2.getPlatformAuthorizeId(), "D1-1存档平台角色授权-1-1-06修改平台授权范围(存档）-授权记录ID不能为空", false);
        Assert.isNull(platformAuthorize_2.getSubjectLifeCycle(), "D1-1存档平台角色授权-1-1-06修改平台授权范围(存档）-主体生命周期不能为空", false);
        Assert.isNull(platformAuthorize_2.getIsArchive(), "D1-1存档平台角色授权-1-1-06修改平台授权范围(存档）-是否存档不能为空", false);
        bOOLEAN_2 = mPlatformAuthorizeService.updatePlfAuth(platformAuthorize_2);


        ArchivePltRoleAuthRespDto retData = new ArchivePltRoleAuthRespDto();


        return retData;
    }

    /**
     * D1-1查询平台授权范围列表[580]
     * gen by moon at 8/10/2022, 2:34:59 PM
     */
    @Trace(operationName = "D1-1查询平台授权范围列表")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Transactional(rollbackFor = Exception.class)
    @Override
    public QueryPlfAuthListRespDto queryPlfAuthList(QueryPlfAuthListReqDto reqDto) {


        List<PlatformAuthorize> listPlatformAuthorize_1 = new ArrayList<>();
//步骤0: 1-1-06查询平台授权范围列表 - queryPlfAuthList
        List<PlatformAuthorize> listPlatformAuthorize = new ArrayList<>();
        QueryPlfAuthListReq queryPlfAuthListReq = new QueryPlfAuthListReq();
        if (reqDto != null) {
            queryPlfAuthListReq.setTypeCode(reqDto.getTypeCode());//sourceId:35241_1
            queryPlfAuthListReq.setAuthorizedObject(reqDto.getAuthorizedObject());//sourceId:35236_1
            queryPlfAuthListReq.setIsArchive(reqDto.getIsArchive());//sourceId:35242_1
        }

        /*1-1-06查询平台授权范围列表[1355]   */

        listPlatformAuthorize = mPlatformAuthorizeService.queryPlfAuthList(queryPlfAuthListReq);

        listPlatformAuthorize_1 = listPlatformAuthorize;

        QueryPlfAuthListRespDto retData = new QueryPlfAuthListRespDto();
        retData.setPlfAuthList(listPlatformAuthorize_1.stream().map(item -> BeanUtil.toBean(item, PlfAuthDto.class)).collect(Collectors.toList()));//sourceId:35246_1


        return retData;
    }

    /**
     * D1-1查询角色授权列表[1434]
     * gen by moon at 10/2/2022, 12:04:30 AM
     */
    @Trace(operationName = "D1-1查询角色授权列表")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Transactional(rollbackFor = Exception.class)
    @BanAuto
    @Override
    public QueryPltRoleAuthListRespDto queryPltRoleAuthList(QueryPltRoleAuthListReqDto reqDto) {


        List<PlatformAuthorize> listPlatformAuthorize_1 = new ArrayList<>();
        List<SceneRole> listSceneRole_1 = new ArrayList<>();
//步骤0: 1-1-06查询平台授权范围列表 - queryPlfAuthList
        List<PlatformAuthorize> listPlatformAuthorize = new ArrayList<>();
        QueryPlfAuthListReq queryPlfAuthListReq = new QueryPlfAuthListReq();
        queryPlfAuthListReq.setTypeCode("ROLE");//sourceId:33854_1
        queryPlfAuthListReq.setAuthorizeTypeCode("SENCE");//sourceId:33850_1
        if (reqDto != null) {
            queryPlfAuthListReq.setAuthorizedObject(reqDto.getAuthorizedObject());//SimpleFieldAssign//sourceId:33851_1
            queryPlfAuthListReq.setIsView(reqDto.getIsView());//SimpleFieldAssign//sourceId:33853_1
            queryPlfAuthListReq.setSubjectLifeCycle(reqDto.getSubjectLifeCycle());//SimpleFieldAssign//sourceId:34953_1
            queryPlfAuthListReq.setIsArchive(reqDto.getIsArchive());//SimpleFieldAssign//sourceId:33887_1
        }

        /*1-1-06查询平台授权范围列表[1355]   */
        Assert.isNull(queryPlfAuthListReq.getTypeCode(), "D1-1查询角色授权列表-1-1-06查询平台授权范围列表-授权内容类型编码不能为空", false);
        Assert.isNull(queryPlfAuthListReq.getAuthorizeTypeCode(), "D1-1查询角色授权列表-1-1-06查询平台授权范围列表-授权对象类型编码不能为空", false);
        listPlatformAuthorize = mPlatformAuthorizeService.queryPlfAuthList(queryPlfAuthListReq);


        listPlatformAuthorize_1 = listPlatformAuthorize;

//步骤1: 1-2-08批量查询角色列表 - batchQueryRoleList
        List<SceneRole> listSceneRole = new ArrayList<>();
        if (listPlatformAuthorize != null && listPlatformAuthorize.size() > 0) {
            BatchQueryRoleListReq batchQueryRoleListReq = new BatchQueryRoleListReq();
            batchQueryRoleListReq.setRoleList(listPlatformAuthorize.stream().map(item -> item.getAuthorizedContentId())
                    .collect(Collectors.toList()));/*list-to-strings*///sourceId:33856_1
            if (reqDto != null) {
                batchQueryRoleListReq.setRoleType(reqDto.getRoleType());//SimpleFieldAssign//sourceId:33890_1
                batchQueryRoleListReq.setPlatformData(reqDto.getPlatformData());//SimpleFieldAssign//sourceId:33891_1
                batchQueryRoleListReq.setSubjectLifeCycle(reqDto.getSubjectLifeCycle());//SimpleFieldAssign//sourceId:34963_1
            }

            /*1-2-08批量查询角色列表[700]   */

            listSceneRole = mSceneRoleService.batchQueryRoleList(batchQueryRoleListReq);


            listSceneRole_1 = listSceneRole;
        }

        QueryPltRoleAuthListRespDto retData = new QueryPltRoleAuthListRespDto();
        //数据集融合  MoreListToOneSource
        if (listPlatformAuthorize_1 != null && !CollectionUtil.isEmpty(listPlatformAuthorize_1)) {
            for (PlatformAuthorize platformAuthorize : listPlatformAuthorize_1) {
                PlfAuthDto retElm = new PlfAuthDto();
                retElm.setPlatformAuthorizeId(platformAuthorize.getPlatformAuthorizeId());//SimpleFieldAssign//sourceId:15283_2
                retElm.setAuthorizedContentId(platformAuthorize.getAuthorizedContentId());//SimpleFieldAssign//sourceId:15284_2
                retElm.setSubjectLifeCycle(platformAuthorize.getSubjectLifeCycle());//SimpleFieldAssign//sourceId:15357_2
                retElm.setOperationInductionId(platformAuthorize.getOperationInductionId());//SimpleFieldAssign//sourceId:15299_2
                retElm.setOperateTime(platformAuthorize.getOperateTime());//SimpleFieldAssign//sourceId:15300_2

                if (listSceneRole_1 != null) {
                    for (SceneRole sceneRole : listSceneRole_1) {
                        if (sceneRole.getRoleId().equals(platformAuthorize.getAuthorizedContentId())) {
                            retElm.setAutomaticCreation(sceneRole.getAutomaticCreation());//SimpleFieldAssign//sourceId:15360_2
                            retElm.setPlatformData(sceneRole.getPlatformData());//SimpleFieldAssign//sourceId:15791_2
                            retElm.setRoleType(sceneRole.getRoleType());//SimpleFieldAssign//sourceId:15358_2
                            retElm.setIsIdentity(sceneRole.getIsIdentity());//SimpleFieldAssign//sourceId:15359_2
                            retElm.setRoleCode(sceneRole.getRoleCode());//SimpleFieldAssign//sourceId:15285_2
                            retElm.setRoleName(sceneRole.getRoleName());//SimpleFieldAssign//sourceId:15286_2
                            retElm.setRoleLogo(sceneRole.getRoleLogo());//SimpleFieldAssign//sourceId:15824_2
                            retData.getPlfAuthList().add(retElm);
                        }
                    }
                }

            }
        }//sourceId:33929_1


        return retData;
    }

    /**
     * D1-1查询授权权限列表（边界）[1574]
     * gen by moon at 10/2/2022, 12:12:57 AM
     */
    @Trace(operationName = "D1-1查询授权权限列表（边界）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Transactional(rollbackFor = Exception.class)
    @Override
    public QueryPltAuthPowerListRespDto queryPltAuthPowerList(QueryPltAuthPowerListReqDto reqDto) {


        List<Privacy> listPrivacy_1 = new ArrayList<>();
//步骤0: 1-1-06查询平台授权范围列表 - queryPlfAuthList
        List<PlatformAuthorize> listPlatformAuthorize = new ArrayList<>();
        QueryPlfAuthListReq queryPlfAuthListReq = new QueryPlfAuthListReq();
        queryPlfAuthListReq.setTypeCode("AUTH");//sourceId:45481_1
        queryPlfAuthListReq.setAuthorizeTypeCode("SENCE");//sourceId:45475_1
        queryPlfAuthListReq.setAuthorizedObject(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSceneId());//CURRENT_SCENEID//sourceId:45476_1
        queryPlfAuthListReq.setIsView("TRUE");//sourceId:45480_1
        queryPlfAuthListReq.setSubjectLifeCycle("CURRENTLY_VALID");//sourceId:45477_1

        /*1-1-06查询平台授权范围列表[1355]   */
        Assert.isNull(queryPlfAuthListReq.getTypeCode(), "D1-1查询授权权限列表（边界）-1-1-06查询平台授权范围列表-授权内容类型编码不能为空", false);
        Assert.isNull(queryPlfAuthListReq.getAuthorizeTypeCode(), "D1-1查询授权权限列表（边界）-1-1-06查询平台授权范围列表-授权对象类型编码不能为空", false);
        Assert.isNull(queryPlfAuthListReq.getAuthorizedObject(), "D1-1查询授权权限列表（边界）-1-1-06查询平台授权范围列表-授权对象ID不能为空", false);
        Assert.isNull(queryPlfAuthListReq.getIsView(), "D1-1查询授权权限列表（边界）-1-1-06查询平台授权范围列表-空间是否可见不能为空", false);
        Assert.isNull(queryPlfAuthListReq.getSubjectLifeCycle(), "D1-1查询授权权限列表（边界）-1-1-06查询平台授权范围列表-主体生命周期不能为空", false);
        listPlatformAuthorize = mPlatformAuthorizeService.queryPlfAuthList(queryPlfAuthListReq);


//步骤1: 1-2-11批量查询权限列表 - batchQueryPowerList
        List<Privacy> listPrivacy = new ArrayList<>();
        if (listPlatformAuthorize != null && listPlatformAuthorize.size() > 0) {
            BatchQueryPowerListReq batchQueryPowerListReq = new BatchQueryPowerListReq();
            batchQueryPowerListReq.setPowerIdList(listPlatformAuthorize.stream().map(item -> item.getAuthorizedContentId())
                    .collect(Collectors.toList()));/*list-to-strings*///sourceId:45484_1
            batchQueryPowerListReq.setSubjectLifeCycle("CURRENTLY_VALID");//sourceId:45487_1
            if (reqDto != null) {
                batchQueryPowerListReq.setStrategyType(reqDto.getStrategyType());//SimpleFieldAssign//sourceId:45490_1
            }

            /*1-2-11批量查询权限列表[1245]   */
            Assert.isNull(batchQueryPowerListReq.getStrategyType(), "D1-1查询授权权限列表（边界）-1-2-11批量查询权限列表-分配策略不能为空", false);
            Assert.isNull(batchQueryPowerListReq.getSubjectLifeCycle(), "D1-1查询授权权限列表（边界）-1-2-11批量查询权限列表-主体生命周期不能为空", false);
            listPrivacy = mPrivacyService.batchQueryPowerList(batchQueryPowerListReq);


            listPrivacy_1 = listPrivacy;
        }

        QueryPltAuthPowerListRespDto retData = new QueryPltAuthPowerListRespDto();
        retData.setFrameworkPrivacyList(listPrivacy_1.stream().map(item -> BeanUtil.toBean(item, FrameworkPrivacyDto.class)).collect(Collectors.toList()));//objList-to-objLists//sourceId:45493_1


        return retData;
    }

    /**
     * D1-1存档权限授权[1562]
     * gen by moon at 10/2/2022, 12:11:48 AM
     */
    @Trace(operationName = "D1-1存档权限授权")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Transactional(rollbackFor = Exception.class)
    @Override
    public ArchivePlfPowerAuthRespDto archivePlfPowerAuth(ArchivePlfPowerAuthReqDto reqDto) {


        //步骤0: 1-1-06修改平台授权范围 - updatePlfAuth
        boolean bOOLEAN;
        PlatformAuthorize platformAuthorize = new PlatformAuthorize();
        platformAuthorize.setSubjectLifeCycle("ARCHIVING");//sourceId:51821_1
        platformAuthorize.setIsArchive("TRUE");//sourceId:51822_1
        if (reqDto != null) {
            platformAuthorize.setPlatformAuthorizeId(reqDto.getPlatformAuthorizeId());//SimpleFieldAssign//sourceId:51816_1
        }

        /*1-1-06修改平台授权范围[1563]   */
        Assert.isNull(platformAuthorize.getPlatformAuthorizeId(), "D1-1存档权限授权-1-1-06修改平台授权范围-授权记录ID不能为空", false);
        Assert.isNull(platformAuthorize.getSubjectLifeCycle(), "D1-1存档权限授权-1-1-06修改平台授权范围-主体生命周期不能为空", false);
        Assert.isNull(platformAuthorize.getIsArchive(), "D1-1存档权限授权-1-1-06修改平台授权范围-是否存档不能为空", false);
        bOOLEAN = mPlatformAuthorizeService.updatePlfAuth(platformAuthorize);


        ArchivePlfPowerAuthRespDto retData = new ArchivePlfPowerAuthRespDto();


        return retData;
    }

    /**
     * D1-1查询权限授权详情[581]
     * gen by moon at 10/2/2022, 7:43:07 AM
     */
    @Trace(operationName = "D1-1查询权限授权详情")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Transactional(rollbackFor = Exception.class)
    @Override
    public QueryPlfPowerAuthDetailRespDto queryPlfPowerAuthDetail(QueryPlfPowerAuthDetailReqDto reqDto) {


        PlatformAuthorize platformAuthorize_1 = null;
        Privacy privacy_1 = null;
//步骤0: 1-1-06查询平台授权范围详情 - queryPlfAuthDetail
        PlatformAuthorize platformAuthorize = null;
        QueryPlfAuthDetailReq queryPlfAuthDetailReq = new QueryPlfAuthDetailReq();
        if (reqDto != null) {
            queryPlfAuthDetailReq.setPlatformAuthorizeId(reqDto.getPlatformAuthorizeId());//SimpleFieldAssign//sourceId:13262_1
        }

        /*1-1-06查询平台授权范围详情[28]   */
        Assert.isNull(queryPlfAuthDetailReq.getPlatformAuthorizeId(), "D1-1查询权限授权详情-1-1-06查询平台授权范围详情-授权记录ID不能为空", false);
        platformAuthorize = mPlatformAuthorizeService.queryPlfAuthDetail(queryPlfAuthDetailReq);


        platformAuthorize_1 = platformAuthorize;

//步骤1: 1-2-11查询权限详情 - queryPowerDetail
        Privacy privacy = null;
        if (platformAuthorize != null) {
            QueryPowerDetailReq queryPowerDetailReq = new QueryPowerDetailReq();
            if (platformAuthorize != null) {
                queryPowerDetailReq.setPrivacyId(platformAuthorize.getAuthorizedContentId());//SimpleFieldAssign//sourceId:13364_1
            }

            /*1-2-11查询权限详情[120]   */
            Assert.isNull(queryPowerDetailReq.getPrivacyId(), "D1-1查询权限授权详情-1-2-11查询权限详情-权限ID不能为空", false);
            privacy = mPrivacyService.queryPowerDetail(queryPowerDetailReq);


            privacy_1 = privacy;
        }

        QueryPlfPowerAuthDetailRespDto retData = new QueryPlfPowerAuthDetailRespDto();
        if (platformAuthorize_1 != null) {
            retData.setPlatformAuthorizeId(platformAuthorize_1.getPlatformAuthorizeId());//SimpleFieldAssign//sourceId:13404_1
            retData.setTypeCode(platformAuthorize_1.getTypeCode());//SimpleFieldAssign//sourceId:34271_1
            retData.setAuthorizedContentId(platformAuthorize_1.getAuthorizedContentId());//SimpleFieldAssign//sourceId:13405_1
            retData.setAuthorizeTypeCode(platformAuthorize_1.getAuthorizeTypeCode());//SimpleFieldAssign//sourceId:34272_1
            retData.setAuthorizedObject(platformAuthorize_1.getAuthorizedObject());//SimpleFieldAssign//sourceId:13406_1
            retData.setIsView(platformAuthorize_1.getIsView());//SimpleFieldAssign//sourceId:34274_1
            retData.setIsDefault(platformAuthorize_1.getIsDefault());//SimpleFieldAssign//sourceId:34275_1
            retData.setSubjectLifeCycle(platformAuthorize_1.getSubjectLifeCycle());//SimpleFieldAssign//sourceId:13407_1
            retData.setOperationInductionId(platformAuthorize_1.getOperationInductionId());//SimpleFieldAssign//sourceId:13408_1
            retData.setOperateTime(platformAuthorize_1.getOperateTime());//SimpleFieldAssign//sourceId:13409_1
        }
        if (privacy_1 != null) {
            retData.setPrivacyCode(privacy_1.getPrivacyCode());//SimpleFieldAssign//sourceId:13424_1
            retData.setPrivacyName(privacy_1.getPrivacyName());//SimpleFieldAssign//sourceId:13418_1
            retData.setPrivacyIntroduce(privacy_1.getPrivacyIntroduce());//SimpleFieldAssign//sourceId:13419_1
            retData.setPrivacyLogo(privacy_1.getPrivacyLogo());//SimpleFieldAssign//sourceId:13420_1
            retData.setPrivacyType(privacy_1.getPrivacyType());//SimpleFieldAssign//sourceId:13421_1
            retData.setStrategyType(privacy_1.getStrategyType());//SimpleFieldAssign//sourceId:13422_1
            retData.setIsportPrivacy(privacy_1.getIsportPrivacy());//SimpleFieldAssign//sourceId:44207_1
            retData.setPrivacyRoute(privacy_1.getPrivacyRoute());//SimpleFieldAssign//sourceId:13423_1
            retData.setIsDataPrivacy(privacy_1.getIsDataPrivacy());//SimpleFieldAssign//sourceId:44208_1
            retData.setDataModel(privacy_1.getDataModel());//SimpleFieldAssign//sourceId:34276_1
            retData.setPrivacyCategory(privacy_1.getPrivacyCategory());//SimpleFieldAssign//sourceId:44209_1
            retData.setBusinessPurposes(privacy_1.getBusinessPurposes());//SimpleFieldAssign//sourceId:44210_1
        }


        return retData;
    }

    /**
     * D1-1查询授权角色列表（边界）[1594]
     * gen by moon at 10/2/2022, 12:13:52 AM
     */
    @Trace(operationName = "D1-1查询授权角色列表（边界）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Transactional(rollbackFor = Exception.class)
    @Override
    public QueryPltAuthRoleListRespDto queryPltAuthRoleList(QueryPltAuthRoleListReqDto reqDto) {


        List<SceneRole> listSceneRole_1 = new ArrayList<>();
//步骤0: 1-1-06查询平台授权范围列表 - queryPlfAuthList
        List<PlatformAuthorize> listPlatformAuthorize = new ArrayList<>();
        QueryPlfAuthListReq queryPlfAuthListReq = new QueryPlfAuthListReq();
        queryPlfAuthListReq.setTypeCode("ROLE");//sourceId:46081_1
        queryPlfAuthListReq.setAuthorizeTypeCode("SENCE");//sourceId:46075_1
        queryPlfAuthListReq.setAuthorizedObject(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSceneId());//CURRENT_SCENEID//sourceId:46076_1
        queryPlfAuthListReq.setIsView("TRUE");//sourceId:46091_1
        queryPlfAuthListReq.setSubjectLifeCycle("CURRENTLY_VALID");//sourceId:46077_1

        /*1-1-06查询平台授权范围列表[1355]   */

        listPlatformAuthorize = mPlatformAuthorizeService.queryPlfAuthList(queryPlfAuthListReq);


//步骤1: 1-2-08批量查询角色列表 - batchQueryRoleList
        List<SceneRole> listSceneRole = new ArrayList<>();
        if (listPlatformAuthorize != null && listPlatformAuthorize.size() > 0) {
            BatchQueryRoleListReq batchQueryRoleListReq = new BatchQueryRoleListReq();
            batchQueryRoleListReq.setRoleList(listPlatformAuthorize.stream().map(item -> item.getAuthorizedContentId())
                    .collect(Collectors.toList()));/*list-to-strings*///sourceId:46085_1
            batchQueryRoleListReq.setSubjectLifeCycle("CURRENTLY_VALID");//sourceId:46086_1
            batchQueryRoleListReq.setRoleType("SYSTERM_ROLE");//sourceId:46089_1
            batchQueryRoleListReq.setIsIdentity("FALSE");//sourceId:46088_1

            /*1-2-08批量查询角色列表[700]   */
            Assert.isNull(batchQueryRoleListReq.getSubjectLifeCycle(), "D1-1查询授权角色列表（边界）-1-2-08批量查询角色列表-主体生命周期不能为空", false);
            Assert.isNull(batchQueryRoleListReq.getRoleType(), "D1-1查询授权角色列表（边界）-1-2-08批量查询角色列表-角色类型不能为空", false);
            Assert.isNull(batchQueryRoleListReq.getIsIdentity(), "D1-1查询授权角色列表（边界）-1-2-08批量查询角色列表-是否身份角色不能为空", false);
            listSceneRole = mSceneRoleService.batchQueryRoleList(batchQueryRoleListReq);


            listSceneRole_1 = listSceneRole;
        }

        QueryPltAuthRoleListRespDto retData = new QueryPltAuthRoleListRespDto();
        retData.setRoleList(listSceneRole_1.stream().map(item -> BeanUtil.toBean(item, FrameworkSceneRoleDto.class)).collect(Collectors.toList()));//objList-to-objLists//sourceId:46092_1


        return retData;
    }
    //
}
